<!--
 * @Date: 2020-01-06 09:28:29
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2020-05-08 16:14:41
 * @describe: -客源-跟进记录-
 -->
<template>
  <el-card shadow="never" class="aui-card--fill">
    <div class="mod-customer__customerfollow}">
      <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
        <!-- <el-form-item>
          <el-input v-model="dataForm.id" placeholder="id" clearable></el-input>
        </el-form-item>
        <el-form-item>
          <el-button @click="getDataList()">{{ $t('query') }}</el-button>
        </el-form-item>
        <el-form-item>
          <el-button type="info" @click="exportHandle()">{{ $t('export') }}</el-button>
        </el-form-item>

        <el-form-item>
          <el-button v-if="$hasPermission('contract:housefollow:delete')" type="danger" @click="deleteHandle()">{{ $t('deleteBatch') }}</el-button>
        </el-form-item>-->
        <el-row>
          <el-col :span="19">
            <el-form-item>
              时间：
              <el-select
                v-model="dataForm.date"
                @change="dateSelectChange"
                class="FormSelect"
                clearable
              >
                <el-option label="自定义" value="6"></el-option>
                <el-option label="当天" value="1"></el-option>
                <el-option label="本周" value="2"></el-option>
                <el-option label="本月" value="3"></el-option>
                <el-option label="本季度" value="4"></el-option>
                <el-option label="今年" value="5"></el-option>
              </el-select>&nbsp;
              <el-date-picker
                v-model="dataForm.createDates"
                type="date"
                placeholder="开始时间"
                value-format="yyyy-MM-dd"
                style="width:136px"
                :disabled="dataForm.date!='6'"
              ></el-date-picker>
              {{' -'}}
              <el-date-picker
                v-model="dataForm.createDatee"
                type="date"
                placeholder="结束时间"
                value-format="yyyy-MM-dd"
                style="width:136px"
                :disabled="dataForm.date!='6'"
              ></el-date-picker>
            </el-form-item>

            <el-form-item>
              部门：
              <el-cascader
                class="FormSelect"
                v-model="deptSelectVal"
                :options="this.$store.state.DeptList"
                :show-all-levels="false"
                @change="deptIdChange"
                :props="deptProps"
                ref="myCascader"
                clearable
              ></el-cascader>-
              <el-select v-model="dataForm.userId" placeholder="人员" class="FormSelect" clearable>
                <el-option
                  v-for="item in maintainList"
                  :key="item.id"
                  :label="item.realName"
                  :value="item.id"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item>
              跟进方式
              <ren-select
                v-model="dataForm.type"
                dict-type="customerFollowType"
                placeholder="跟进方式"
                class="FormSelect"
              ></ren-select>
            </el-form-item>
            <el-form-item>
              <el-button @click="Reset">重置</el-button>
            </el-form-item>
            <el-form-item>
              <el-button
                v-if="$hasPermission('contract:housefollow:delete')"
                type="danger"
                @click="deleteHandle()"
              >删除跟进</el-button>
            </el-form-item>
          </el-col>
          <el-col :span="5">
            搜索：
            <el-input
              placeholder="请输入内容"
              v-model="dataForm.search"
              class="input-with-select"
              @keyup.enter.native="getDataList"
              clearable
              style="width:70%"
            >
              <el-button slot="append" icon="el-icon-search" @click="getDataList"></el-button>
            </el-input>
          </el-col>
        </el-row>
      </el-form>
      <el-table
        v-loading="dataListLoading"
        :data="dataList"
        :height="autoTabHeight"
        border
        @selection-change="dataListSelectionChangeHandle"
        style="width: 100%;"
      >
        <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
        <el-table-column prop="customerId" label="编号" header-align="center" align="center">
          <template
            slot-scope="scope"
          >{{"KY - "+scope.row.impId.substring(scope.row.impId.length-6)}}</template>
        </el-table-column>
        <el-table-column prop="type" label="跟进方式" header-align="center" align="center">
          <template slot-scope="scope">
            <span>{{ $getDictLabel("customerFollowType", scope.row.type) }}</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="content"
          min-width="350%"
          label="跟进内容"
          header-align="center"
          align="center"
        ></el-table-column>
        <el-table-column prop="deptName" label="部门" header-align="center" align="center"></el-table-column>
        <el-table-column prop="creatorName" label="跟进人" header-align="center" align="center"></el-table-column>
        <el-table-column prop="createDate" label="跟进时间" header-align="center" align="center"></el-table-column>
        <!-- <el-table-column :label="$t('handle')" fixed="right" header-align="center" align="center" width="150">
          <template slot-scope="scope">
            <el-button v-if="$hasPermission('customer:customerfollow:update')" type="text" size="small" @click="addOrUpdateHandle(scope.row.id)">{{ $t('update') }}</el-button>
            <el-button v-if="$hasPermission('customer:customerfollow:delete')" type="text" size="small" @click="deleteHandle(scope.row.id)">{{ $t('delete') }}</el-button>
          </template>
        </el-table-column>-->
      </el-table>
      <div class="paginationBox">
        <el-pagination
          :current-page="page"
          :page-sizes="[10, 20, 50, 100]"
          :page-size="limit"
          :total="total"
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="pageSizeChangeHandle"
          @current-change="pageCurrentChangeHandle"
        ></el-pagination>
      </div>

    </div>
  </el-card>
</template>

<script>
import mixinViewModule from "@/mixins/view-module";
export default {
  mixins: [mixinViewModule],
  data() {
    return {
      mixinViewModuleOptions: {
        createdIsNeed: false,
        getDataListURL: "/resource/resourcecustomerimport/pageFollow",
        getDataListIsPage: true,
        deleteIsBatch: true
      },
      dataForm: {
        customerId: this.$route.query.ID,
        customerType: this.$route.query.customerType,
        userId: this.$route.query.userId ? this.$route.query.userId : "",
        type: "",
        date: "6",
        createDates: "",
        createDatee: "",
        deptId: "", //部门
        search: "",
        state: ""
      },
      deptSelectVal: "",
      deptProps: {
        value: "id",
        label: "name",
        checkStrictly: true
      },
      maintainList: this.$store.state.maintainList
    };
  },
  created() {
    this.autoWidth();
     if (this.$route.query.statisticType) {
      this.statisticOpen();
    } else {
      this.getDataList();
    }
  },
  mounted() {
    let _this = this;
    window.onresize = function() {
      _this.autoWidth();
    };
  },
  methods: {
    autoWidth() {
      let w = document.documentElement.clientWidth || document.body.clientWidth;
      let h =
        document.documentElement.clientHeight || document.body.clientHeight;
      if (w > 1610 && w < 1670) {
        this.autoTabHeight = h - 285;
      } else if (w < 1610) {
        this.autoTabHeight = h - 320;
      } else {
        this.autoTabHeight = h - 240;
      }
    },
    // 日期方式切换
    dateSelectChange(val) {
      if (val != "6") {
        this.dataForm.createDates = "";
        this.dataForm.createDatee = "";
      }
    },
     //统计跳转
    statisticOpen() {
     if (this.$route.query.customerModuleId == 2) {
          let statisticType = this.$route.query.statisticType;
          if (statisticType == 1) {
            this.dataForm.userId = this.$route.query.id;
          } else {
            this.deptSelectVal = this.$route.query.id;
            this.dataForm.deptId = this.$route.query.id;
          }
          this.dataForm.userId =="",
          this.dataForm.transactionType = this.$route.query.transactionType;
          this.dataForm.date = this.$route.query.date;
          this.dataForm.createDates = this.$route.query.createDates;
          this.dataForm.createDatee = this.$route.query.createDatee;
        }
    },
    deptIdChange(val) {
      let a = "";
      if (this.$refs.myCascader.getCheckedNodes()[0]) {
        a = this.$refs.myCascader.getCheckedNodes()[0].value;
        this.dataForm.deptId = a;
        this.getUserList(a);
      } else {
        this.dataForm.deptId = "";
      }
    },
    Reset() {
      this.dataForm = {
        customerId: "",
        customerType: "",
        userId: "",
        type: "",
        date: "6",
        createDates: "",
        createDatee: "",
        deptId: "", //部门
        search: "",
        state: ""
      };
    },
    // 获取部门员工列表
    getUserList(deptId) {
      let _this = this;
      this.$http
        .get(`/sys/user/deptUserList`, {
          params: {
            deptId: deptId
          }
        })
        .then(({ data: res }) => {
          if (res.code !== 0) {
            return this.$message.error(res.msg);
          }
          _this.maintainList = res.data;
        })
        .catch(() => {});
    }
  },
  watch: {
    dataForm: {
      handler(nowVal, oldVal) {
        this.getDataList();
      },
      deep: true
    },
    $route(to, from) {
      if (to.name == "customerPage") {
       
        this.dataForm.customerId = this.$route.query.ID;
        this.dataForm.customerType = this.$route.query.customerType;
        this.dataForm.userId = this.$route.query.userId;
        this.query();
      } else if (to.name == "customer-page-customerfollow") {
        if (this.$route.query.customerModuleId == 2) {
          let statisticType = this.$route.query.statisticType;
            this.dataForm.userId ="";
          if (statisticType == 1) {
            this.dataForm.userId = this.$route.query.id;
          } else {
            this.deptSelectVal = this.$route.query.id;
            this.dataForm.deptId = this.$route.query.id;
          }
        
          this.dataForm.transactionType = this.$route.query.transactionType;
          this.dataForm.date = this.$route.query.date;
          this.dataForm.createDates = this.$route.query.createDates;
          this.dataForm.createDatee = this.$route.query.createDatee;
        }
        // this.query();
      }
    }
  }
};
</script>
